﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class GamesManager : Singleton<GamesManager> 
{
	protected GamesManager () {}
	
	[System.Serializable]
	public class m_ScenesToLoadClass
	{
		public string m_SceneName;
		public m_ScenesID m_SceneId;
	}
	
	public m_ScenesToLoadClass[] m_ScenesToLoad;

	public enum m_ScenesID
	{
		MainMenu = 0,
		TroubleGame,
		ChessGame,
		ObstacleRace,
		AllGames
	};
	
	public int m_NbOfPlayers = 2;
	public int m_NbOfCPU = 2;

	public Sprite[] m_PlayersIcon;
	public Color[] m_PlayersColor;

	//private List<int> m_ScenesToLoad = new List<int>(); 

	private float m_ScreenWidth;
	private float m_ScreenHeight;

	private GenericGame m_CurrentGame;
	private int m_RandomSeed;
	
	public float ScreenWidth {get { return m_ScreenWidth; }}
	public float ScreenHeight {get { return m_ScreenHeight; }}
	public GenericGame CurrentGame {get { return m_CurrentGame; } set { m_CurrentGame = value; }}
	public int NbOfPlayers {get { return m_NbOfPlayers; } set { m_NbOfPlayers = value; }}

	private void Awake()
	{
		m_DontDestroyOnLoad = true;
		base.Awake();
		//if(singleton == null)
		//{
		//	singleton = gameObject;
		//}
		//if(singleton.name == gameObject.name)
		//{
		//	DontDestroyOnLoad(gameObject);
		//}

		//if (FindObjectsOfType(typeof(GamesManager)).Length > 1)
		//{
		//	Debug.Log("UIM: Already found instance of script in scene; destroying.");
		//	DestroyImmediate(gameObject);
		//}
		//
		//DontDestroyOnLoad(gameObject);

		Vector3 size = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0f));
		m_ScreenWidth = size.x;
		m_ScreenHeight = size.y;

		m_RandomSeed =  System.Environment.TickCount;
		Random.seed = m_RandomSeed;

		//for(int i = 1; i < m_SceneID.AllGames; i++)
		//{
			//m_ScenesToLoad.Add(i);
		//}
		//Debug.Log(m_RandomSeed);
	}

	void Start () 
	{
	}
	   
	void Update () 
	{
	
	}

	public string PlayerOrderToString(int order)
	{
		string player = "Player ";
		switch(order)
		{
		case 0:
			return player + "One";
		case 1:
			return player + "Two";
		case 2:
			return player + "Three";
		case 3:
			return player + "Four";
		default:
			break;
		}

		return null;
	}
}
